package com.itheima.controller;

import com.itheima.entity.*;
import com.itheima.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
public class ClassController {

    @Autowired
    private ClassService classService;

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/clazzs")
    public Result page(ClassQueryParam  param){
        PageBean pageBean = classService.page(param);

        return Result.success(pageBean);
    }

    /**
     * 添加班级
     * @param clazz
     * @return
     */
    @PostMapping("/clazzs")
    public Result add(@RequestBody Clazz clazz){
        classService.add(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     * @param id
     * @return
     */
    @DeleteMapping("/clazzs/{id}")
    public Result delete(@PathVariable Integer id){
        classService.deleteById(id);
        return Result.success();
    }

    /**
     * 根据id查询班级
     * @param id
     * @return
     */
    @GetMapping("/clazzs/{id}")
    public Result selectById(@PathVariable Integer id){
        Clazz clazz = classService.selectById(id);
        return Result.success(clazz);
    }

    /**
     * 更新班级信息
     * @param clazz
     * @return
     */
    @PutMapping("/clazzs")
    public Result update(@RequestBody Clazz clazz){
        classService.update(clazz);
        return Result.success();
    }

    /**
     * 查询所有班级信息
     * @return
     */
    @GetMapping("/clazzs/list")
    public Result selectAll(){
        List<Clazz> clazzs =  classService.selectAll();
        return Result.success(clazzs);
    }

    /**
     * 查询所有员工信息
     * @return
     */
    @GetMapping("/emps/list")
    public Result findEmplist(){
        List<Emp> emps = classService.selectEmp();
        return Result.success(emps);
    }

}
